import React from 'react';
import {message, Table} from 'antd'
class TableTemplete extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            query:props.query,
            dataSource:{rows:[],total:0},
            columns:props.columns,
            rowKey:props.rowKey
         };
    }
    componentWillMount(){
        this.getList(this.state.query)
        this.props.onRef(this)
    }
    getList=(query)=>{
        if(this.props.getData){
            query.page = (query.current-1)*query.pageSize
        this.props.getData(query).then(r=>{
            if(r&&r.status===200){
                this.setState({
                    dataSource:r.data
                })
                this.props.setTotal(r.data.total)
            }
            else{
                message.error(r.msg)
            }
        })}
    }

    render() {
        let {columns,dataSource,rowKey} = this.state
        return (
            <div>
                <Table columns={columns} dataSource={dataSource.rows} bordered rowKey={rowKey} pagination={false}></Table>
            </div>
            
        );
    }
}

export default TableTemplete;